import React, { Component } from 'react'
import axios from 'axios'
export default class Son extends Component {
    // state = {
    //     timer: null
    // }
    timer = null;
    render() {
        // console.log('son1-render'); 
        return (
            <div id='son1'>Son1--{this.props.num}</div>
        )
    }
    handleClickFn() {
        console.log('document');
    }

    controller = new AbortController(); // 请求控制器
    componentDidMount() {
        // const timer = setInterval(() => { console.log('秦涵请自重!!') }, 1000)
        // this.setState({
        //     timer: timer
        // })
        //this.timer = setInterval(() => { console.log('秦涵请自重!!') }, 1000)

        // document.onclick = function () {
        //     console.log('document');
        // }

        // document.addEventListener('click', this.handleClickFn)

        // 发起数据请求
        axios.get('https://api.i-lynn.cn/college', {
            signal: this.controller.signal
        }).then(res => {
            console.log('son1-res', res);
        }).catch(err => { })


        console.log('son1-componentDidMount');
    }
    componentWillUnmount() {
        console.log('son1-componentWillUnmount');
        // 清除定时器
        //clearInterval(this.timer)
        // 清除事件
        //document.onclick = null
        // document.removeEventListener('click', this.handleClickFn)
        // 取消数据请求
        //this.controller.abort()
    }
}
